<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <form action="/upload" method="post" enctype="multipart/form-data">
    <input type="file" id="file" name="file">
    <img src="" width="100" id="img" alt="">
    <button type="submit">上传</button>
  </form>
  <script>
    var file = document.querySelector('#file');
    var oImg = document.querySelector('#img');
    file.onchange = function(){
      // this.files[0]
      var fd = new FileReader();
      fd.readAsDataURL(this.files[0]);
      fd.onload = function(){
        oImg.src = this.result;
      }
    }
  </script>
</body>
</html>